package org.dtrd.modules.shop.controller;


import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.dtrd.common.aspect.annotation.AutoLog;
import org.dtrd.modules.shop.entity.bean.GlucometerGetDetail;
import org.dtrd.modules.shop.entity.bean.GlucometerGetListInfo;
import org.dtrd.modules.shop.entity.bean.GlucometerGetListRequest;
import org.dtrd.modules.shop.entity.bean.GlucometerGetPageRequest;
import org.dtrd.modules.shop.entity.request.GlucometerPhotoRequest;
import org.dtrd.modules.shop.service.IDtrdEntShcRdGlucometerGetService;
import org.dtrd.common.api.vo.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RestController;
import org.dtrd.base.BaseController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List;

import static org.dtrd.common.constant.CommonConstant.*;
import static org.dtrd.config.system.SystemState.ResponseState.*;

/**
 * <p>
 * 血糖仪领用表 前端控制器
 * </p>
 * @author xiao
 * @since 2022-06-29
 */
@RestController
@RequestMapping("/glucometerget")
@Api(tags = "血糖仪领用")
public class DtrdEntShcRdGlucometerGetController extends BaseController {

    @Autowired
    private IDtrdEntShcRdGlucometerGetService glucometerGetService;

    @ApiOperation(value = "分页查询血糖仪领用表列表", response = GlucometerGetListInfo.class)
    @PostMapping("/list")
    @AutoLog(value="查询血糖仪领用表列表", operateType = OPERATE_TYPE_QUERY)
    public Result<?> getGlucometerGetList(@RequestBody @Validated GlucometerGetPageRequest request){
        handlePageRequest(request);
        IPage<GlucometerGetListInfo> page = glucometerGetService.pageGlucometerGet(request);
        return Result.OK(page);
    }

    @ApiOperation(value = "保存旧血糖仪设备照片")
    @PostMapping("/photo")
    public Result<?> saveOldGlucometerPhoto(@RequestBody @Validated GlucometerPhotoRequest request) {
        boolean result = glucometerGetService.saveOldGlucometerPhoto(request);
        return result ? Result.OK() : error(STATE_OPERATION_FAILURE);
    }
}
